<template>
    <div>
        <input type="text" placeholder="请输入用户名" v-model="username"/>
        <input type="password" placeholder="请输入密码" v-model="password"/>
        <div  @click="login" class="login">登录</div>
    </div>
</template>
<script type="text/babel">
    import API from '../../api/api.js'
    import qs from 'qs'
    const api=new API();
    export default{
        data(){
            return{
                username:'13165988540',
                password:'6437120',
            }
        },
        methods:{
            login(){
                let param={
                    username:this.username,
                    password:this.password,
                    clientType: 'GENERAL'
                };
                const response=api.getToken(qs.stringify(param));
                response.then((res)=>{
                    if(res.code===200){
                        sessionStorage.setItem('access_token',res.result.access_token);
                        sessionStorage.setItem('token_type',res.result.token_type);
                        this.$router.push({path:'/test'})
                    }else{
                        console.log('密码错误');
                    }
                }).catch(()=>{
                    console.log('用户名或密码错误');
                })
            }
        }
    }
</script>
<style scoped>
    input{
        width:100%;
        height:0.4rem;
    }
    .login{
        width:100%;
        height:0.2rem;
        text-align: center;
        color: #000;
    }
</style>
